/*
 *   The node composed of the MyHashTree
 * 
 *       done by Lee in 2013/1/29
 */
package lee.base.structure;

import java.util.HashMap;

public class MyNode {
	protected String attribute = null;
	protected String value = null;
	protected HashMap<String, MyNode> next = null;
	
	public MyNode() {}
	/**
	 * adding attribute name of this node
	 * @param attr - String
	 */
	public void ACT001_addAttribute(String attr) {
		this.attribute = attr;
	}
	/**
	 * adding value of this node when only the node is a leave
	 * @param value - String
	 */
	public void ACT002_addValue(String value) {
		if(this.next == null) {
			this.value = value;
		}
	}
	/**
	 * adding the next node pointer
	 * @param addAttr : the attribute name of new node - String
	 * @param addNode : the new node you want to add - MyNode
	 */
	public void ACT003_addAttrNext(String addAttr, MyNode addNode) {
        if(this.value == null) {
			if(this.next == null) {  //first creating the HashMap
				this.next = new HashMap<String, MyNode>();
			}
			this.next.put(addAttr, addNode);
		}
	}
	/**
	 * get instance variable - value
	 * @return String
	 */
	public String GET001_value() {
		return this.value;
	}
	/**
	 * get the specific next node based on the attribute, if not exist, return null
	 * @param attribute - String
	 * @return MyNode or null
	 */
	public MyNode GET002_NextNode(String attribute) {
		if(this.next != null) {
		    return this.next.get(attribute);
		}
		else {
			return null;
		}
	}
	/**
	 * get instance variable - attribute
	 * @return String
	 */
	public String GET003_attribute() {
		return this.attribute;
	}
	/**
	 * get next list
	 * @return HashMap
	 */
	public HashMap<String, MyNode> GET004_next() {
		return this.next;
	}
	/**
	 * set instance variable - value
	 * @param value - String
	 */
	public void SET001_value(String value) {
		this.value = value;
	}
}